<?php 
namespace common\service;
use think\Queue;
class QueueService{

	public static $instance = null;
	public static $queueMaps = array(
        // 
        'AssetJob' => 'common\queue\jobs\AssetJob@assetJob',
        'UserSteamJob' => 'common\queue\jobs\UserSteamJob@userSteamJob',
        'AssetOutJob' => 'common\queue\jobs\AssetOutJob@assetOutJob',
	);
	public $adapter = 'mail';
	
	private function __construct(){
	}
	private function checkQueueName($queueName){
		if(key_exists($queueName, self::$queueMaps)){
			return false;
		}
		return true;
	}
	public static function getInstance(){
		if(self::$instance == null){
			self::$instance = new self();
		}
		return self::$instance;
	}
	public function setAdapter($adapter){
		$this->adapter = $adapter;
		return $this;
	}

	public function assetJob($botInvId)
	{
		if($this->adapter == 'AssetJob'){
			Queue::push(self::$queueMaps['AssetJob'], $botInvId, $queue = 'AssetJob');
		}
	}

	public function userSteamJob($steamId)
	{
		if($this->adapter == 'UserSteamJob'){
			Queue::push(self::$queueMaps['UserSteamJob'], $steamId, $queue = 'UserSteamJob');
		}
	}

	public function assetOutJob($userId, $botInvIds)
	{
		if($this->adapter == 'AssetOutJob'){
			$data = array(
				'user_id' => $userId,
				'bot_inv_ids' => $botInvIds,
			);

			Queue::push(self::$queueMaps['AssetOutJob'], $data, $queue = 'AssetOutJob');
		}
	}
}